#include "network.h"

int sysfs(dev *d){
    dev p;
    struct sysfs_class *net = NULL;
    struct dlist *devices = NULL;
    struct sysfs_class_device *device = NULL;
   
    net = sysfs_open_class("net");
    if (net == NULL)
        return (1);

    devices = sysfs_get_class_devices(net);
    if (devices == NULL)
        return (2);

    int i = 0;
    dlist_for_each_data(devices, device, struct sysfs_class_device){
                            p = (dev) malloc(sizeof(struct s));
                            strcpy(p->name,(*device).name);
                            if (!(*d)) {
                                *d = p;
                                (*d)->pr = NULL;
                            }
                            else{
                               p->pr = *d;
                               *d = p;
                            }   
    }
    sysfs_close_class(net);
    return(0);
}

int dhcp(char f[])
{
    if (f[strlen(f)-4] != 'd')
        return 0;
    if (f[strlen(f)-3] != 'h')
        return 0;
    if (f[strlen(f)-2] != 'c')
        return 0;
    if (f[strlen(f)-1] != 'p')
        return 0;
    return 1;
}

gchar* text_combo(char f[])
 {
    int j = 0, i  = 6;
    char inter[10];
    while (f[i] != ' ')
    {
        inter[j] = f[i];
        i++;
        j++;
    }
    inter[j] = '\0';
    return inter;
}

int col_combo(GtkWidget *combo, char f[])
{
    gint i = 0;
    gchar* txt;
    while(1)
    {
        gtk_combo_box_set_active (combo, i);
        txt = gtk_combo_box_get_active_text (combo);
        if (!strcmp(txt,f))
            return i;
        i++;
        
    }
}